
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rotempco.Core.ORM.ADAL;
using System.Data.SqlClient;
using Rotempco.BaseClass.Objects.EntityObjects;
using Rotempco.Core.ORM.Objects;
using Rotempco.Core.ORM.Objects.Enums;
using Rotempco.Core.ORM.Logic;
using Rotempco.Core.Logic;




namespace Rotempco.BaseClass.DAL
{
    public partial class EmailQueueData : ADAL<EmailQueue, long>
    {
	    #region [ ADATA Implementation ]

        protected override string GetTableName()
        {
            return "EmailQueue";
        }

        protected override Pair<string, string> GetIdentity()
        {
            return new Pair<string, string>("EmailQueueId", SymbolExtensions.GetPropertyName((EmailQueue d) => d.EmailQueueId));
        }

        protected override List<ORMParameter> GetORMMapping()
        {
            List<ORMParameter> mapping = new List<ORMParameter>();
		
			mapping.Add(new ORMParameter("SenderName", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SenderName)));
			mapping.Add(new ORMParameter("SenderAddress", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SenderAddress)));
			mapping.Add(new ORMParameter("RecipientAddress", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.RecipientAddress)));
			mapping.Add(new ORMParameter("Subject", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.Subject)));
			mapping.Add(new ORMParameter("Message", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.Message)));
			mapping.Add(new ORMParameter("DoNotSendBefore", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.DoNotSendBefore)));
			mapping.Add(new ORMParameter("SentDate", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SentDate)));
			mapping.Add(new ORMParameter("SentErrorDate", SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SentErrorDate)));

            return mapping;
        }

        #endregion

        #region [ GetBy ]

        public EmailQueue GetSingle(bool getDeleted = false, long? emailQueueId = null, string senderName = null, string senderAddress = null, string recipientAddress = null, string subject = null, string message = null, DateTime? doNotSendBefore = null, DateTime? sentDate = null, DateTime? sentErrorDate = null , bool? doNotSendBeforeIsNull = null, bool? sentDateIsNull = null, bool? sentErrorDateIsNull = null)
        {
            List<PropertyPair> parameterList = GetByParameterList(emailQueueId: emailQueueId, senderName: senderName, senderAddress: senderAddress, recipientAddress: recipientAddress, subject: subject, message: message, doNotSendBefore: doNotSendBefore, sentDate: sentDate, sentErrorDate: sentErrorDate);
            List<NullablePair> nullablePairList = GetNullablePairList(doNotSendBeforeIsNull: doNotSendBeforeIsNull, sentDateIsNull: sentDateIsNull, sentErrorDateIsNull: sentErrorDateIsNull);
            return GetBy(parameterList, getDeleted, nullablePairList: nullablePairList).SingleOrDefault();
        }

        public List<EmailQueue> GetList(bool getDeleted = false, long? getFirstEntries = null, long? getLastEntries = null, long? emailQueueId = null, string senderName = null, string senderAddress = null, string recipientAddress = null, string subject = null, string message = null, DateTime? doNotSendBefore = null, DateTime? sentDate = null, DateTime? sentErrorDate = null , bool? doNotSendBeforeIsNull = null, bool? sentDateIsNull = null, bool? sentErrorDateIsNull = null)
        {
            List<PropertyPair> parameterList = GetByParameterList(emailQueueId: emailQueueId, senderName: senderName, senderAddress: senderAddress, recipientAddress: recipientAddress, subject: subject, message: message, doNotSendBefore: doNotSendBefore, sentDate: sentDate, sentErrorDate: sentErrorDate);
            List<NullablePair> nullablePairList = GetNullablePairList(doNotSendBeforeIsNull: doNotSendBeforeIsNull, sentDateIsNull: sentDateIsNull, sentErrorDateIsNull: sentErrorDateIsNull);
            return GetBy(parameterList, getDeleted, getFirstEntries, getLastEntries, nullablePairList: nullablePairList);
        }

        #endregion

        #region [ Private ]

        private List<PropertyPair> GetByParameterList(long? emailQueueId = null, string senderName = null, string senderAddress = null, string recipientAddress = null, string subject = null, string message = null, DateTime? doNotSendBefore = null, DateTime? sentDate = null, DateTime? sentErrorDate = null)
        {
            List<PropertyPair> mapping = new List<PropertyPair>();

			mapping.Add(new PropertyPair(emailQueueId, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.EmailQueueId)));
			mapping.Add(new PropertyPair(senderName, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SenderName)));
			mapping.Add(new PropertyPair(senderAddress, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SenderAddress)));
			mapping.Add(new PropertyPair(recipientAddress, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.RecipientAddress)));
			mapping.Add(new PropertyPair(subject, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.Subject)));
			mapping.Add(new PropertyPair(message, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.Message)));
			mapping.Add(new PropertyPair(doNotSendBefore, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.DoNotSendBefore)));
			mapping.Add(new PropertyPair(sentDate, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SentDate)));
			mapping.Add(new PropertyPair(sentErrorDate, SymbolExtensions.GetPropertyPair((EmailQueue d) => d.SentErrorDate)));

            return mapping;
        }

        private List<NullablePair> GetNullablePairList(bool? doNotSendBeforeIsNull = null, bool? sentDateIsNull = null, bool? sentErrorDateIsNull = null)
        {
            List<NullablePair> nullablePairList = new List<NullablePair>();

			if (doNotSendBeforeIsNull.HasValue)
                nullablePairList.Add(new NullablePair(PropertyLogic.GetPropertyName((EmailQueue c) => c.DoNotSendBefore),doNotSendBeforeIsNull.Value));
			if (sentDateIsNull.HasValue)
                nullablePairList.Add(new NullablePair(PropertyLogic.GetPropertyName((EmailQueue c) => c.SentDate),sentDateIsNull.Value));
			if (sentErrorDateIsNull.HasValue)
                nullablePairList.Add(new NullablePair(PropertyLogic.GetPropertyName((EmailQueue c) => c.SentErrorDate),sentErrorDateIsNull.Value));


            if (nullablePairList.Count <= 0)
                return null;

            return nullablePairList;
        }

        #endregion

	}
}

